// import { roleSearch,roleAdd} from './types'
import request from "@/service/request";
import {PromiseResponse} from "@/service/api/type.ts";
import {SysPermissionVo} from "@/service/api/system/permission/type.ts";

/**
 * 获取权限树
 * @param query
 */
const getPermissionTree = (query: any): PromiseResponse<SysPermissionVo[]> => {
  return request({
    url: "/system/permission/list",
    method: "get",
    params: query,
  });
};

/**
 * 新增权限
 * @param query
 */
const addPermission = (query: any): PromiseResponse<any> => {
  return request({
    url: "/system/permission",
    method: "post",
    data: query,
  });
};

/**
 * 关键字获取父节点
 * @param query
 */
const getParentArr = (query: string): PromiseResponse<SysPermissionVo[]> => {
  return request({
    url: `/system/permission/list?name=${query}`,
    method: "get",
  });
};

/**
 * 根据权限id获取详细信息
 * @param id
 */
const getPermissionDetail = (id: string): PromiseResponse<SysPermissionVo> => {
  return request({
    url: `/system/permission/${id}`,
    method: "get",
  });
};

/**
 * 修改权限详情
 * @param query
 */
const updatePermission = (query: any): PromiseResponse<any> => {
  return request({
    url: "/system/permission",
    method: "put",
    data: query,
  });
};

/**
 * 删除权限
 * @param id
 */
const deletePermission = (id: string | string[]): PromiseResponse<any> => {
  return request({
    url: `/system/permission/${id}`,
    method: "delete",
  });
};

/**
 * 刷新权限
 */
const refresh = (): PromiseResponse<any> => {
  return request({
    url: "/system/permission/refresh",
    method: "post",
  });
};

/**
 * 获取所有二级页面
 * @param query
 */
const getAllPages = (query: any): PromiseResponse<SysPermissionVo[]> => {
  return request({
    url: "/system/permission/list",
    method: "GET",
    params: query
  });
};

/**
 * 移动权限
 * @param parentId
 * @param permissionIds
 */
const movePermissions = (parentId: string, permissionIds: any): PromiseResponse<any> => {
  return request({
    url: `/system/permission/move/${parentId}`,
    method: "post",
    data: permissionIds
  });
};

/**
 * 复制权限
 * @param parentId
 * @param query
 */
const copyPermissions = (parentId: string, query: any): PromiseResponse<any> => {
  return request({
    url: `/system/permission/copy/${parentId}`,
    method: "post",
    data: query
  });
};

export {
  getPermissionTree,
  addPermission,
  getParentArr,
  getPermissionDetail,
  updatePermission,
  deletePermission,
  refresh,
  getAllPages,
  movePermissions,
  copyPermissions
};
